package com.itheima.duofa;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Objects;
import java.util.Scanner;

/**
 * 目标：创建客户端，发送数据给服务端
 */
public class Client {

    public static void main(String[] args) throws Exception {
        //1.创建客户端Socket对象，与指定的服务器端建立连接（通信管道）
        Socket clientScoket = new Socket("127.0.0.1",10086);

        //2.获取Socket的输出流对象
        OutputStream os = clientScoket.getOutputStream();
        PrintWriter pw = new PrintWriter(os);

        Scanner sc = new Scanner(System.in);
        //多发
        while ( true){
            System.out.println("请输入要发送的数据：");
            String msg = sc.next();
            pw.write(msg);
            if (Objects.equals(msg, "886")){
                System.out.println("客户端端口。。。");
                break;
            }
        }
        //3.写数据给服务器


        //4.资源释放
        pw.close(); //关闭输出流
        clientScoket.close(); //关闭Socket
    }
}
